﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;
using MySql.Data;

namespace DAL
{
    public class DALUser
    {
        User user;
        MySqlConnection mysql;
        DoSQL doSql = new DoSQL();
        public DALUser(User user)
        {
            
            mysql = doSql.mysql;
            this.user = user;
        }

        public bool checklogin()
        {
            doSql.openmysql();
            string sql = string.Format("select * from user  u where u.username='{0}' and u.user_password='{1}'", user.username, user.password);
            MySqlCommand comm = new MySqlCommand(sql, mysql);
            MySqlDataReader reader = comm.ExecuteReader();
            reader.Read();

            if (reader.HasRows)
            {
                reader.Close();
                doSql.closemysql();
                return true;
            }
            else
            {
                reader.Close();
                doSql.closemysql();
                return false;
            }
        }

        public void InsertUser()
        {
            doSql.openmysql();
            string sql = string.Format("insert into user(username,user_password) values ('{0}','{1}');", user.username, user.password);
            MySqlCommand comm = new MySqlCommand(sql, mysql);
            comm.ExecuteNonQuery();
            doSql.closemysql();
        }
    }
}
